<template>
  <el-dialog :title="title" :visible.sync="show" append-to-body :close-on-click-modal="false" width="1200px" @closed="closed">
    <el-table :data="list" size="small">
      <el-table-column label="所属部门" prop="showDeptName" width="250" />
      <el-table-column label="项目" prop="projectName" width="150" />
      <el-table-column label="项目(检查口径)" prop="inpectionCaliber" width="110" />
      <el-table-column label="检查单位" align="center" width="80" key="rdcType" v-if="hasRdcType">
        <dict-tag slot-scope="{ row }" :options="dict.type.cq_eval_rdc_type" :value="row.rdcType" />
      </el-table-column>
      <el-table-column label="检查得分" min-width="300">
        <template slot-scope="{ row }">
          <ScoreDisplay :value="row" :cfg="cfgInfo" />
        </template>
      </el-table-column>
      <el-table-column label="检查日期" align="center" prop="checkDate" width="100" />
      <el-table-column label="锁定状态" align="center" width="70">
        <el-tag slot-scope="{ row }" size="small" :type="row.isLockout ? 'primary' : 'info'">{{ row.isLockout ? '锁定' : '未锁' }}</el-tag>
      </el-table-column>
    </el-table>
    <div slot="footer">
      <el-button type="primary" @click="onConfirm">继续录入</el-button>
      <el-button @click="show = false">取消录入</el-button>
    </div>
  </el-dialog>
</template>
<script>
// 相似数据确认
import ScoreDisplay from './ScoreDisplay'
export default {
  components: { ScoreDisplay },
  dicts: ['cq_eval_rdc_type'],
  data() {
    return {
      show: false,
      hasRdcType: false,
      cfgInfo: {},
      list: []
    }
  },
  computed: {
    title() {
      return `当前已有${this.list.length}条相似的成绩，是否要继续录入该成绩？`
    }
  },
  methods: {
    closed() {
      this.hasRdcType = false
      this.cfgInfo = {}
      this.list = []
    },
    open({ cfgInfo = {}, data = {} }) {
      this.hasRdcType = !!this.$route.query?.rdcType
      this.cfgInfo = cfgInfo

      // 处理列表数据
      const list = data.duplicateList || []
      const deptName = i => [i.deptName1, i.deptName2, i.deptName3].filter(i => i).join(' - ')
      list.map(i => (i.showDeptName = deptName(i)))
      this.list = list

      this.show = true
    },
    onConfirm() {
      this.show = false
      this.$emit('confirm')
    }
  }
}
</script>
